
package ex1;

public class CountWithBug {

	public static int count(int[] numbers) {
		int count=0; 	//block 1
		for(int i=0; i<numbers.length; i++) {	//block 2
			int x = numbers[i];					//block 3
			if( x < 0) {						//block 4
				if (x <= -1 && i > 0 && numbers[i-1] == -1) {	//block 5
					break;										//end block 5
				}
			} else {
				count++;										//block6
			}
		}
		return count;	//block7
	}
	
	/*	NEW BUG:
	 *	Clearly, there is a bug in the program now, it will quit on
	 *	two negative numbers if the 1st is -1 (i.e. 2,6,1,7,-1,-6,2,7).
	 *	No prime test can test this since the prime test requires a simple path.
	 *	So there's no chance of checking ...5,2,3,4,5,2,... - There's a loop here
	 *	which cases it not to run as a simple path.
	 *	In this case - all test (T1-T5 passes - only the program is with bugs).
	 */
	
	/* OLD BUG:
	 *  Explanation: Clearly, there is a bug in the program now,
	 *  because when facing two consecutive (-1), the program
	 *  will increament count once more before breaking.
	 *  No prime path can reach that point because it requires
	 *  at least two element in the array, which means entering
	 *  the for loop twice, which means the path isn't prime.
	 *  Therefore, no Prime Paths coverage can  detect that bug.
	 */
}
